package view.render.monster
{
	import enums.main.UISize;
	
	import feathers.controls.Label;
	
	import model.vo.monster.LMonsterAttackVo;
	
	import starling.display.Image;
	import starling.display.Sprite;
	import starling.text.TextField;
	import starling.utils.Color;
	
	import util.AtlasTextureGenerator;
	
	import view.render.BaseScrollerItem;
	
	
	/**
	 * 大型怪物-攻击方式列表item
	 * @author £iang
	 * 
	 */	
	public class LMonsterAttackListItem extends BaseScrollerItem
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 伤害信息 */
		public var damageLabel:Label;
		/** 威力信息 */
		public var powerLabel:Label;
		/** 气绝信息 */
		public var dizzyLabel:Label;
		/** 参考信息 */
		public var psLabel:TextField;
		/** 异常属性图标组 */
		public var attributeGroup:Sprite;
		
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 初始化函数 
		 * 
		 */		
		override protected function initializeOther():void
		{
			super.initializeOther();
			damageLabel = new Label();
			damageLabel.textRendererProperties.wordWrap = true;
			scollerContainer.addChild( damageLabel );
			
			attributeGroup = new Sprite();
			scollerContainer.addChild( attributeGroup );
			
			powerLabel = new Label();
			powerLabel.textRendererProperties.wordWrap = true;
			scollerContainer.addChild( powerLabel );
			
			dizzyLabel = new Label();
			dizzyLabel.textRendererProperties.wordWrap = true;
			scollerContainer.addChild( dizzyLabel );
			
			psLabel = new TextField(
				UISize.MAIN_W * 0.5, 
				_itemH * UISize.DPI_SCALE,
				"", "微软雅黑,宋体", 24 * UISize.DPI_SCALE, Color.WHITE
			);
			psLabel.vAlign = "center";
			psLabel.hAlign = "left";
			scollerContainer.addChild( psLabel );
		}
		
		/**
		 * 调整组件 
		 * 
		 */		
		override protected function draw():void
		{
			var labelY:Number = ( _itemH - 
				43 ) / 2 * UISize.DPI_SCALE;
			var padding:Number = UISize.TITLE_PADDING_LEFT * UISize.DPI_SCALE;
			var firstLabelFullW:Number;
			
			firstLabel.x = padding;
			firstLabelFullW = UISize.MAIN_W * _firstPercent;
			
			damageLabel.y = labelY;
			damageLabel.x = 0;
			damageLabel.width  = UISize.MAIN_W * 0.25;
			
			powerLabel.y = labelY;
			powerLabel.x = UISize.MAIN_W * 0.5;
			powerLabel.width  = UISize.MAIN_W * 0.25;
			
			dizzyLabel.y = labelY;
			dizzyLabel.x = UISize.MAIN_W * 0.75;
			dizzyLabel.width  = UISize.MAIN_W * 0.25;
			
			psLabel.x = UISize.MAIN_W;
			psLabel.width = UISize.MAIN_W * 0.5;
			
			attributeGroup.x = UISize.MAIN_W * 0.25;
			attributeGroup.y = ( _itemH - 30 ) / 2 * UISize.DPI_SCALE;
			
			scollerContainer.x = firstLabelFullW;
			scollerContainer.height = _itemH * UISize.DPI_SCALE;
			scollerContainer.width = UISize.MAIN_W - firstLabelFullW;
			
			this.width = UISize.MAIN_W;
			this.height = _itemH * UISize.DPI_SCALE;
		}
		
		/**
		 * 设置item数据 
		 * @param data 数据
		 * 
		 */		
		public function setData( data:LMonsterAttackVo ):void
		{
			firstLabel.text = data.attack;
			damageLabel.text = data.damage;
			powerLabel.text = data.power;
			dizzyLabel.text = data.dizzy;
			psLabel.text = data.ps;
			
			var len:int = data.attribute.length;
			
			for ( var i:int = 0; i < len; i ++ )
			{
				var tmpImage:Image = new Image(
					AtlasTextureGenerator.getAttributeTextureById( data.attribute[ i ] )
				);
				
				tmpImage.scaleX = tmpImage.scaleY = UISize.DPI_SCALE;
				tmpImage.x = 37 * UISize.DPI_SCALE * i;
				attributeGroup.addChild( tmpImage );
			}
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 析构滚动条容器中的标签 
		 * 
		 */		
		protected override function disposeAnythingInContainer():void
		{
			disposeLabels( [
				"damage", "power",
				"dizzy", "ps"
			] );
			
			var image:Image;
			var k:int;
			
			for ( k = 0; k < attributeGroup.numChildren; k ++ )
			{
				if ( attributeGroup.getChildAt( k ) is Image )
				{
					image = attributeGroup.getChildAt( k ) as Image;
					image.dispose();
					image.texture.dispose();
					image = null;
				}
			}
			
			attributeGroup.dispose();
			attributeGroup = null;
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function LMonsterAttackListItem()
		{
			super();
			_itemH = UISize.LMONSTER_ATK_ITEM_H;
			_firstPercent = 0.5;
			initialize();
		}
	}
}